# -*- coding: utf-8 -*-
from django.contrib import admin
from main.models import Employee
from trainings.models import TrainingsRSIS, TrainingsWORK

class TrainingsRSISAdmin(admin.ModelAdmin):
    list_display = ['title', 'date']

    def formfield_for_manytomany(self, db_field, request, **kwargs):
        if db_field.name == "employees":
            kwargs["queryset"] = Employee.objects.filter(worker_or_rsis='R')
        return super(TrainingsRSISAdmin, self).formfield_for_manytomany(db_field, request, **kwargs)

admin.site.register(TrainingsRSIS, TrainingsRSISAdmin)

class TrainingsWORKAdmin(admin.ModelAdmin):
    list_display = ['pk', 'title', 'date']
    list_display_links = ['pk', 'title']
    filter_horizontal = ['employees']

    def formfield_for_manytomany(self, db_field, request, **kwargs):
        if db_field.name == "employees":
            kwargs["queryset"] = Employee.objects.filter(worker_or_rsis__startswith='W')
        return super(TrainingsWORKAdmin, self).formfield_for_manytomany(db_field, request, **kwargs)

admin.site.register(TrainingsWORK, TrainingsWORKAdmin)


  